package com.briup.web.servlet;

import com.briup.bean.Book;
import com.briup.service.IBookService;
import com.briup.service.impl.BookServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "BookServlet", value = "/bookInfo")
public class BookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        IBookService bookService = new BookServiceImpl();
        //第一步：接收参数
        Integer bookId = Integer.valueOf(req.getParameter("bookId"));
        System.out.println("接收到的bookId为"+bookId);
//        调用service层方法
        Book book = bookService.findBookById(bookId);
//        存入session
        HttpSession session = req.getSession();
        session.setAttribute("bookInfo",book);
//        跳转并显示
        resp.sendRedirect("/viewBook.jsp");
    }

}
